import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class CheckOutFrame extends JDialog {	
	//	Local Variables
	private JPanel _mainPanel,_topPanel,_centerPanel,_bottomPanel;
	private JLabel _ageLbl, _costLbl, _nameLbl, _amountLbl;
	private JList _goodsList;
	private JScrollPane _goodsScroll;
	private JButton _close;
	
	//	Peer objects
	private Person _person;
	
	public CheckOutFrame(JFrame _parent, Person aPerson)
	{
		super(_parent, true);
		_person = aPerson;
		initializeGUI();
		setLayout();
		this.setTitle("Check Out");
		this.setResizable(false);
		this.setSize(200,275);
		this.setVisible(true);
	}
	
	private void initializeGUI()
	{	
		_mainPanel = new JPanel(new BorderLayout());
		_topPanel = new JPanel(new GridLayout(2,1));
		_centerPanel = new JPanel();
		_bottomPanel = new JPanel(new BorderLayout());
		_ageLbl = new JLabel("Age: " + _person.get_age());
		_costLbl = new JLabel("Total cost: " + _person.get_totalCost() + "kr");
		_nameLbl = new JLabel("Name: " + _person.get_name());
		_amountLbl = new JLabel("Amount of Goods: " + _person.get_numOfItems());
		_goodsList = new JList(_person.get_shoppingBasket());
		_goodsScroll = new JScrollPane(_goodsList);
		_close = new JButton("Close");
		_close.addActionListener(new CancleListener());
	}
	
	private void setLayout()
	{
		_mainPanel.add(_topPanel, BorderLayout.NORTH);
		_mainPanel.add(_centerPanel, BorderLayout.CENTER);
		_mainPanel.add(_bottomPanel, BorderLayout.SOUTH);
		_topPanel.add(_nameLbl);
		_topPanel.add(_ageLbl);
		_centerPanel.add(_goodsScroll);
		_bottomPanel.add(_amountLbl, BorderLayout.NORTH);
		_bottomPanel.add(_costLbl, BorderLayout.CENTER);
		_bottomPanel.add(_close, BorderLayout.SOUTH);
		this.add(_mainPanel);
	}
	
	private class CancleListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent e) 
		{
			setVisible(false);
		}
	}
}
